package org.muninn.niagara.conversion;

import javax.baja.status.BStatusEnum;
import javax.baja.status.BStatusNumeric;
import javax.baja.status.BStatusString;
import javax.baja.sys.BComponent;
import javax.baja.sys.BDynamicEnum;
import javax.baja.sys.BIcon;
import javax.baja.sys.Context;
import javax.baja.sys.Flags;
import javax.baja.sys.Property;
import javax.baja.sys.Sys;
import javax.baja.sys.Type;

public class BEnumDeconstruct extends BComponent
{
  /** Enum input to be deconstructed **/
  public static final Property in = newProperty(Flags.SUMMARY, new BStatusEnum());
  public void setIn(BStatusEnum v) { set(in, v); }
  public BStatusEnum getIn() { return (BStatusEnum) get(in); }
  
  /** Output representing the ordinal of <code>in</code> **/
  public static final Property ordinal = newProperty(Flags.SUMMARY|Flags.READONLY, new BStatusNumeric());
  public void setOrdinal(BStatusNumeric v) { set(ordinal, v); }
  public BStatusNumeric getOrdinal() { return (BStatusNumeric) get(ordinal); }
  
  /** Output representing the tag associated with the ordinal of <code>in</code> **/
  public static final Property tag = newProperty(Flags.SUMMARY|Flags.READONLY, new BStatusString());
  public void setTag(BStatusString v) { set(tag, v); }
  public BStatusString getTag() { return (BStatusString) get(tag); }
  
  public void started() { deconstruct(); }
  
  public void changed(Property p, Context cx)
  {
    if (!isRunning()) return;
    
    if (p.equals(in)) deconstruct();
  }
  
  public void deconstruct()
  {
    BDynamicEnum currVal = getIn().getValue();
    
    setOrdinal(new BStatusNumeric(currVal.getOrdinal()));
    setTag(new BStatusString(currVal.getTag()));    
  }
  
  public BIcon getIcon() { return icon; }
  private static final BIcon icon = BIcon.make("local:|module://muninn/org/muninn/niagara/graphics/MuninnGroup.PNG");
  
  public static final Type TYPE = Sys.loadType(BEnumDeconstruct.class);
  public Type getType() { return TYPE; }
}
